import { createRouter, createWebHistory } from 'vue-router'

//路由对象
const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes: [
        {
            path: "/",
            redirect:"/login",
            title:'登录'
        },        
        {
        path: "/login",
        name: "login",
        title:'登录',
        component: () => import("../page/Login")
        } ,
        {
            path: "/register",
            name: "register",
            title:'注册',
            component: () => import("../page/Register")
        } ,
        {
            path: "/studentpage",
            name: "studentpage",
            title:'学生页面',
            component: () => import("../page/StudentPage"),
            children:[
                {
                    path: "",
                    name:"stuhome",
                    title:'学生主页面',
                    components:{
                        top:import("../page/StuTop"),
                        default:import("../page/StuBody"),
                    },
                    children:[
                        {
                            path: "homepage",
                            name: "homepage",
                            title:'首页',
                            component: () => import("../page/HomePage")
                        } ,
                        {
                            path: "stucourse",
                            name: "stucourse",
                            title:'课程',
                            component: () => import("../page/StuCourse")
                        } ,
                        {
                            path: "stuclass",
                            name: "stuclass",
                            title:'班级',
                            component: () => import("../page/StuClass")
                        } ,
                        {
                            path: "learningcenter",
                            name: "learningcenter",
                            title:'学习中心',
                            component: () => import("../page/LearninGcenter")
                        } ,
                        {
                            path: "stuusers",
                            name: "stuusers",
                            title:'个人主页',
                            component: () => import("../page/StuUsers")
                        } ,
                    ]
                }
            ]
            
        },
        {
            path: "/forget",
            name: "forget",
            title:'忘记密码',
            component: () => import("../page/Forget")
        } ,
        {
            path: "/marquee",
            name: "marquee",
            title:'走马灯',
            component: () => import("../page/Marquee")
        } ,
        {
            path: "/main",
            name: "main",
            title:'主页面',
            component: () => import("../page/Main"),
            children:[
                {
                    path: "",
                    name:"home",
                    title:'主页面',
                    components:{
                        top:import("../page/Top"),
                        menu:import("../page/Menu"),
                        default:import("../page/Body"),
                    },
                    children:[
                        {
                            path: "department",
                            name: "department",
                            title:'部门表',
                            component: () => import("../page/Department")
                        } ,
                        {
                            path: "oran",
                            name: "oran",
                            title:'组织表',
                            component: () => import("../page/Oran")
                        } ,
                        {
                            path: "teacher",
                            name: "teacher",
                            title:'教师管理',
                            component: () => import("../page/Teacher"),
                        } ,
                        {
                            path: "student",
                            name: "student",
                            title:'学生列表',
                            component: () => import("../page/Student")
                        } ,
                        {
                            path: "users",
                            name: "users",
                            title:'个人主页',
                            component: () => import("../page/Users")
                        } ,
                        {
                            path: "userclass",
                            name: "userclass",
                            title:'我的班级',
                            component: () => import("../page/UserClass")
                        } ,
                        {
                            path: "allclass",
                            name: "allclass",
                            title:'全部班级',
                            component: () => import("../page/AllClass")
                        } ,
                        {
                            path: "usercourse",
                            name: "usercourse",
                            title:'我的课程',
                            component: () => import("../page/UserCourse")
                        } ,
                        {
                            path: "allcourse",
                            name: "allcourse",
                            title:'全部课程',
                            component: () => import("../page/AllCourse")
                        } ,
                        {
                            path: "motifytea",
                            name: "motifytea",
                            component: () => import("../page/MotifyTea")
                        } ,
                        {
                            path: "oran",
                            name: "oran",
                            component: () => import("../page/Oran")
                        },
                        {
                            path: "addtea",
                            name: "addtea",
                            component: () => import("../page/Addtea")
                        } ,
                        {
                            path: "reform",
                            name: "reform",
                            component: () => import("../page/Reform")
                        } ,
                        {
                            path: "newchina",
                            name: "newchina",
                            component: () => import("../page/NewChina")
                        } ,
                        {
                            path: "mks",
                            name: "mks",
                            component: () => import("../page/Mks")
                        } ,
                    ]
                }, 
                
            ]
        }
        
    ]
})

router.beforeEach((to,from,next)=>{
    if(to.path === '/login' || to.path === '/register'|| to.path === '/forget'){
    return next()
    }
    const tokenStr = window.sessionStorage.getItem('token')
    if(tokenStr){
    return next()
    }
    next('/login')
})
    

export default router;